//
//  FindViewModel.m
//  BrushFace
//
//  Created by timer_q on 16/1/26.
//  Copyright © 2016年 Zzz. All rights reserved.
//

#import "FindViewModel.h"

@implementation FindViewModel


/**
 *  获取消息中心，消息列表
 */
- (void)fetchFindListWithRPP:(NSInteger)rpp andCurPage:(NSInteger)curpage andCB:(void(^)(id output))CB{
    NSString *requestStr = [NSString stringWithFormat:@"%@/msg/listmsg.json",SERVICE_ADRESS];
    NSDictionary *params = @{@"curPage":[NSString stringWithFormat:@"%ld",curpage],
                             @"rPP":[NSString stringWithFormat:@"%ld",rpp]};
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [[AFHTTPResponseSerializer alloc] init];
    [manager GET:requestStr parameters:params success:^(AFHTTPRequestOperation * _Nonnull operation, id  _Nonnull responseObject) {
        NSDictionary *jsonObject = [NSJSONSerialization JSONObjectWithData:operation.responseData options:0 error:nil];
        CB(jsonObject);
    } failure:^(AFHTTPRequestOperation * _Nullable operation, NSError * _Nonnull error) {
        
    }];
}

/**
 *  读消息
 */
- (void)readMessageWithId:(NSString *)msgid andCB:(void(^)(id output))CB{
    NSString *requestStr = [NSString stringWithFormat:@"%@/msg/read.json",SERVICE_ADRESS];
    NSDictionary *params = @{@"id":msgid};
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [[AFHTTPResponseSerializer alloc] init];
    [manager GET:requestStr parameters:params success:^(AFHTTPRequestOperation * _Nonnull operation, id  _Nonnull responseObject) {
        NSDictionary *jsonObject = [NSJSONSerialization JSONObjectWithData:operation.responseData options:0 error:nil];
        CB(jsonObject);
    } failure:^(AFHTTPRequestOperation * _Nullable operation, NSError * _Nonnull error) {
        
    }];

}
@end
